﻿/********************************************************************************
** @ Date:2024/02/20
** @ Author: WeiXiaoYu
** @ Description: WebSocket客户端类
** @ Version:1.0.0
** @ Fun:
********************************************************************************/
#ifndef CWebSocketClient_H
#define CWebSocketClient_H
#include <QTcpSocket>
#include <QWebSocket>
#include <QImage>
#include <QMutex>
#include "CInfoExchangeBase.h"

#define def_autoCloseFollow 60000  //自动取消关注时间(ms)

class CWebSocketClient : public QObject
{
    Q_OBJECT
public:
    CWebSocketClient(QObject *parent, QWebSocket *pWebSocket, QString sIp);//传入的是WebSockek客户端
    ~CWebSocketClient();

public:
    //===========Websocket相关============
    QWebSocket *GetWebSocketClient(){ return m_pWebSocket; }//获取QWebSocket客户端指针
    void closeWebSocketClient();//关闭WebSocket客户端
    bool judgeIsThisWebsocketClient(QWebSocket *pWebSocketTemp);//判断传入的QWebSocket是否是是这个Client的

	//==处理请求
	void handleRequest(QString sMsg);
	//回复请求

public slots:
	void slotSendRspMsgString(QString sRspMsgString);   //发送响应数据字符串
	void slotSendRspMsg(SRspDataParam stRspRaram);      //发生响应数据

private slots:
	void slotAutoClose();                                                                          //自动取消关注线程

signals:
    void sigSendMessage(QString strText);

public:
	CInfoExchangeBase* m_pInfoExchange;

private:
	//===========Websocket相关============
	QWebSocket *m_pWebSocket = nullptr;
	QString m_sIp;//客户端请求的Ip地址
	QTimer* m_pAutoCloseTimer;                                                  //自动取消关注定时器
	QQueue<SRspDataParam> m_qDevCtrQueue;                                       //设备指令操作队列
};

#endif // CWebSocketClient_H
